<template>
	<view :class="[isDark?'dark':'', $store.state.AppStyle]" :style="{'background-color':isDark?'#1c1c1c':'#f6f6f6','min-height':isDark?'100vh':'auto'}">
		<view class="header" :style="[{height:CustomBar + 'px'}]">
			<view class="cu-bar" :class="isDark?'dark':'bg-white'" :style="{'height': CustomBar + 'px','padding-top':StatusBar + 'px','background-color':isDark?'#1c1c1c':'#ffffff'}">
				<view class="action" @tap="back">
					<text class="cuIcon-back"></text>
				</view>
				<view class="content" :style="[{top:StatusBar + 'px'}]">
					<text class="text-bold">{{name}}</text>
					<block v-if="type==1">
						<text class="margin-left-xs cuIcon-group"></text>
					</block>
				</view>
				<view class="action">
					<view class="cu-avatar round"  @tap="showModal" data-target="chatInfo" :style="avatarstyle" v-if="avatarstyle!=''"></view>
					<view class="cu-avatar round" v-else>
						<text class="home-noLogin"></text>
					</view>
				</view>
			</view>
		</view>
		<view class="cu-chat" >
			<view class="cu-item"  :style="[{padding:NavBar + 'px 0px 0px 0px'}]"></view>
			<!-- <view class="more-msg">
				<text class="text-blue" @tap="loadMore">{{moreText}}</text>
			</view> -->
			<view class="cu-info" v-if="isFollow==0">
				{{$t('chat.chat.nofollowtxt')}}
			</view>
			<block v-for="(item,index) in msgList">
				<view class="date text-center" style="color: #727272;font-size: 12px;">{{formatDate(item.created)}}  </view>
				<view class="cu-item " :class="item.uid==uid?'self':''" v-if="item.type!=4">
					<view class="cu-avatar radius" @tap="toUserContents(item.userJson)"  v-if="item.uid!=uid" :style="'background-image:url('+item.userJson.avatar+');'"></view>
					<view class="main">
						<block v-if="item.type==0">
							<view class="content shadow break-all" :class="item.uid==uid?'bg-green':''" style="box-shadow: 0px 0px 30px 0px rgba(0, 0, 0, 0.1);" @longtap="ToCopy(item.text)">
								<rich-text :nodes="markHtml(item.text)"></rich-text>
							</view>
						</block>
						<block v-if="item.type==1">
							<image :src="item.url" @tap="previewImage(item.url)" mode="widthFix"></image>
						</block>
						<block v-if="item.type==2">
							<view class="voice-message" @tap="playVoice(item.url)">
								<text class="cuIcon-sound text-blue"></text>
								<text class="voice-text">{{$t('chat.chat.voicemessage')}}</text>
							</view>
						</block>
					</view>
					<view class="cu-avatar radius"  v-if="item.uid==uid" :style="'background-image:url('+item.userJson.avatar+');'"></view>
					<view class="date">
					<block  v-if="group=='administrator'||group=='editor'">
						<text class="admin-btn margin-left-sm">
							<text class="text-red" @tap="toDeleteMsg(item.id)">{{$t('common.delete')}}</text>
							<text class="text-black margin-left-sm" @tap="toBanMsg(item.uid)">{{$t('chat.chat.muted')}}</text>
						</text>
					</block>
					</view>
				</view>
				<view class="cu-info round"  v-if="item.type==4">
					<block v-if="type==1">
						<block v-if="item.text=='ban'">
							{{$t('global.enableallbans')}}
						</block>
						<block v-else>
							{{$t('global.closesallbans')}}
						</block>
					</block>
					<block v-else>
						<block v-if="item.text=='ban'">
							<block v-if="item.uid==uid">
								{{$t('global.blockside')}}
							</block>
							<block v-else>
								{{$t('global.blockedyou')}}
							</block>
						</block>
						<block v-else>
							<block v-if="item.uid==uid">
								{{$t('global.unblockedit')}}
							</block>
							<block v-else>
								{{$t('global.liftblocked')}}
							</block>
						</block>
						
					</block>
				</view>
			</block>
		</view>

		<view class="cu-bar foot input" :style="[{bottom:InputBottom+'px', paddingBottom: '40rpx'}]">
			<view class="action">
				<text class="cuIcon-pic text-grey" @tap="upload"></text>
			</view>
			<view class="action">
				<text class="cuIcon-voice text-grey" @tap="toggleVoiceMode"></text>
			</view>
			<view class="input-container" v-if="!isVoiceMode">
				<input class="solid-bottom" :adjust-position="false" :focus="false" maxlength="300" cursor-spacing="10" @focus="InputFocus" @blur="InputBlur" v-model="msg"/>
			</view>
			<view class="voice-container" v-if="isVoiceMode">
				<!-- H5语音录制：点击开始/结束 -->
				<view class="voice-btn" v-if="isH5" 
					:class="{'recording': isRecording}"
					@tap="toggleH5Record">
					{{voiceBtnText}}
				</view>
				<!-- APP/小程序语音录制：按住说话 -->
				<view class="voice-btn" v-else
					:class="{'recording': isRecording}"
					@touchstart="startRecord" 
					@touchmove="touchMove"
					@touchend="stopRecord" 
					@touchcancel="cancelRecord">
					{{voiceBtnText}}
				</view>
			</view>
			<view class="action">
				<text class="cuIcon-emojifill text-grey" style="margin-right: 20rpx;" @tap="OwO"></text>
			</view>
			<button class="cu-btn bg-green shadow" @tap="sendMsg()" v-if="!isVoiceMode">{{$t('global.send')}}</button>
			
		</view>
		<view class="chat-owo owo" v-if="isOwO" :style="[{bottom:InputBottom+52+'px'}]">
			<scroll-view class="owo-list" scroll-y>
				<view class="owo-main">
					<view class="owo-lit-box" v-for="(item,index)  in owoList" @tap="setOwO(item)" :key="index">
						<image :src="'/'+item.icon" mode="aspectFill"></image>
					</view>
				</view>
				
			</scroll-view>
			<view class="owo-type">
				<view class="owo-box" @tap="toOwO('paopao')" :class="OwOtype=='paopao'?'cur':''">
					{{$t('global.owopaopao')}}
				</view>
				<view class="owo-box" @tap="toOwO('adai')" :class="OwOtype=='adai'?'cur':''">
					{{$t('global.adai')}}
				</view>
				<view class="owo-box" @tap="toOwO('alu')" :class="OwOtype=='alu'?'cur':''">
					{{$t('global.owoalu')}}
				</view>
				<view class="owo-box" @tap="toOwO('quyinniang')" :class="OwOtype=='quyinniang'?'cur':''">
					{{$t('global.owoquyinniang')}}
				</view>
			</view>
		</view>
		<view class="cu-modal" :class="modalName=='chatInfo'?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content"><text class="text-bold">{{name}}</text>
					<block v-if="type==1">
						<text class="margin-left-xs cuIcon-group"></text>
					</block></view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				
					<view class="user-edit-header" v-if="type==0" @tap="goUserInfo(name,toid,0)">
						<image :src="avatar"></image>
					</view>
					<view class="user-edit-header" v-else>
						<image :src="avatar"></image>
					</view>
				<view class="cu-bar bg-white justify-center">
					<view class="action">
						<block v-if="type==0">
							<button class="cu-btn bg-green margin-left" @tap="goHistory()">{{$t('chat.chat.chathistory')}}</button>
							<block v-if="ban==0">
								<button class="cu-btn bg-red margin-left" @tap="toBan(1)">{{$t('chat.chat.shieldother')}}</button>
							</block>
							<block v-if="ban==uid">
								<button class="cu-btn bg-red margin-left" @tap="toBan(0)">{{$t('chat.chat.unblockother')}}</button>
							</block>
							<button class="cu-btn bg-blue margin-left" @tap="toJb(1)">{{$t('chat.chat.reportuser')}}</button>
						</block>
						
						<block v-if="type==1">
							<block  v-if="group=='administrator'||group=='editor'">
								<button class="cu-btn bg-green" @tap="addGroup">{{t('chat.chat.edituserinfo')}}</button>
								<block v-if="ban==0">
									<button class="cu-btn bg-red margin-left" @tap="toBan(1)">{{$t('chat.chat.allmuted')}}</button>
								</block>
								<block v-else>
									<button class="cu-btn bg-red margin-left" @tap="toBan(0)">{{$t('chat.chat.liftspeech')}}</button>
								</block>
								<button class="cu-btn bg-blue margin-left" @tap="toJb(2)">{{$t('chat.chat.reportgroupchat')}}</button>
								<button v-if="uid==groupUser"  class="cu-btn bg-red margin-left" @tap="toDelete()"><text class="cuIcon-delete"></text></button>
							</block>
							<block v-else>
								{{$t('chat.chat.createuser')}}:<text class="text-blue margin-left-sm" @tap="goUserInfo(groupUserName,groupUser,1)">{{groupUserName}}</text>
							</block>
						</block>
					</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import { localStorage } from '../../js_sdk/mp-storage/mp-storage/index.js'
	import darkModeMixin from '@/utils/darkModeMixin.js'
	// #ifdef APP-PLUS
	import owo from '../../static/app-plus/owo/OwO.js'
	// #endif
	// #ifdef H5
	import owo from '../../static/h5/owo/OwO.js'
	// #endif
	// #ifdef MP
	var owo = [];
	// #endif
	export default {
		mixins: [darkModeMixin],
		data() {
			return {
				StatusBar: this.StatusBar,
				CustomBar: this.CustomBar,
				NavBar:this.StatusBar +  this.CustomBar,
				AppStyle:this.$store.state.AppStyle,
				InputBottom: 0,
				chatid:0,
				name:$t('chat.chat.unknownuser'),
				moreText:$t('common.getmore'),
				toid:0,
				avatar:"",
				userInfo:null,
				token:"",
				avatarstyle:"",
				msg:"",
				isFollow:1,
				type:0,
				page:1,
				title:"",
				jb:"",
				msgList:[],
				uid:"",
				
				msgLoading:null,
				lastTime:0,
				
				group:"",
				text:"",
				isOwO:false,
				owo:owo,
				owoList:[],
				owoTextList:[],
				OwOtype:"paopao",
				
				groupUserName:"",
				groupUser:0,
				groupUserAvatar:"",
				
				modalName:"",
				ban:0,
				lastid:0,
				
				// 语音聊天相关
				isVoiceMode: false,
				voiceBtnText: $t('chat.chat.holdtalk'),
				isRecording: false,
				recorderManager: null,
				recordTimer: null,
				recordDuration: 0,
				
				// H5语音录制相关
				h5MediaRecorder: null,
				h5AudioChunks: [],
				h5AudioBlob: null,
				h5Stream: null,
				isH5: false,
				// APP/小程序上划取消相关
				touchStartY: null,
				isCancelRecording: false,
				
			};
		},
		onShow() {
			var that = this
			if(localStorage.getItem('userinfo')){
				that.userInfo = JSON.parse(localStorage.getItem('userinfo'));
				that.uid = that.userInfo.uid;
				that.group = that.userInfo.group;
			}
		},
		onReachBottom() {
		    //触底后执行的方法，比如无限加载之类的
			var that = this;
			//到底部后，重新变成第一页，开始加载数据
			that.page = 1;
		},
		onBackPress() {
			var that = this
			clearInterval(that.msgLoading);
			that.msgLoading = null;
		},
		onUnload() {
			var that = this
			clearInterval(that.msgLoading);
			that.msgLoading = null;
			// 清理H5语音录制资源
			// #ifdef H5
			if (that.h5Stream) {
				that.h5Stream.getTracks().forEach(track => track.stop());
			}
			// #endif
		},
		onLoad(res) {
			var that = this;
			// #ifdef APP-PLUS || MP
			that.NavBar = that.CustomBar;
			// #endif
			// #ifdef H5
			that.isH5 = true;
			// #endif
			if(res.chatid){
				that.chatid = res.chatid;
				that.getMsgList();
				that.setRead();
				that.msgLoading = setInterval(() => {
				 that.getMsgList(false);
				}, 3000);
			}
			if(res.jb){
				if(res.title){
					if(res.text==''){
						that.text = that.$t('chat.chat.nofilledin')
					}else{
						that.text = res.text
					}
					if(res.jb=='user'){
						that.msg = that.$t('chat.chat.reportusertxt') + ':' +res.title + that.$t('chat.chat.reportreason') +':'+that.text
						that.sendMsg()
					}else if(res.jb=='shop'){
						that.msg = that.$t('chat.chat.reportproduct') + ':' +res.title + that.$t('chat.chat.reportreason')+that.text
						that.sendMsg()
					}else if(res.jb=='group'){
						that.msg = that.$t('chat.chat.reportgroup') + ':'+res.title + that.$t('chat.chat.reportreason')+that.text
						that.sendMsg()
					}else if(res.jb=='app'){
						that.msg = that.$t('chat.chat.reportapplication') + ':'+res.title + that.$t('chat.chat.reportreason')+that.text
						that.sendMsg()
					}else{
						that.msg = that.$t('chat.chat.reportoriginal') + ':'+res.title + that.$t('chat.chat.reportreason')+that.text
						that.sendMsg()
					}
				}
			}
			if(res.type){
				that.type = res.type
			}
			if(res.name){
				that.name = res.name
			}
			if(res.uid){
				that.toid = res.uid;
				that.getIsFollow();
			}
			if(that.type==0){
				that.getUserInfo(that.toid);
				that.getGroupInfo(that.chatid);
			}
			if(that.type==1){
				that.getGroupInfo(that.chatid);
			}
			// #ifdef APP-PLUS
			uni.onKeyboardHeightChange(res => {
				//监听软键盘的高度 
				//当点击软键盘自带的收起按钮的时候也就是会隐藏软键盘 这时候监听到的软键盘的高度就是0 、
				//让输入框取消焦点 这时候再去输入内容的时候 输入框就会弹起
				if (res.height == 0) {
					that.InputBottom = 0;
				}else{
					that.InputBottom = res.height;
				}
			});
			// #endif
			// #ifdef APP-PLUS || H5
			//that.owoTextList = that.owo.data.paopao.container;
			var owo = that.owo.data;
			var owoList=[];
			for(var i in owo){
				owoList = owoList.concat(owo[i].container);
			}
			that.owoTextList = owoList;
			that.owoList = that.owo.data.paopao.container;
			// #endif
			// 初始化录音管理器
			// #ifdef APP-PLUS || MP
			that.recorderManager = uni.getRecorderManager();
			that.initRecorder();
			// #endif
			// #ifdef H5
			// H5录音初始化 - 延迟到用户点击录音按钮时进行
			// that.initH5Recorder();
			// #endif
			setTimeout(() => {
				uni.pageScrollTo({
					duration: 0,
					scrollTop: 99999999
				})
			},1000)
		},
		methods: {
			loadMore(){
				var that = this;
				if(that.isLoad==0){
					that.moreText = that.$t('global.loading');
					that.getMsgList(true);
				}
			},
			back(){
				var that = this;
				clearInterval(that.msgLoading);
				that.msgLoading = null
				uni.navigateBack({
					delta: 1
				});
			},
			setRead() {
				var that = this;
				var token = ""
				if(localStorage.getItem('userinfo')){
					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					token=userInfo.token;
				}
				that.$Net.request({
					url: that.$API.msgSetRead(),
					data:{
						"token":token,
						"chatid":that.chatid
					},
					header:{
						'Content-Type':'application/x-www-form-urlencoded'
					},
					method: "get",
					dataType: 'json',
					success: function(res) {
						if(res.data.code==1){
							
						}
					},
					fail: function(res) {
						uni.showToast({
							title: that.$t('common.networkfail'),
							icon: 'none'
						})
					}
				})
			},
			formatDate(datetime) {
				var that = this;
			    var datetime = new Date(datetime * 1000);
			    var now = new Date();
			    var year = datetime.getFullYear(),
			        month = ("" + (datetime.getMonth() + 1)).padStart(2, '0'),
			        date = ("" + datetime.getDate()).padStart(2, '0'),
			        hour = ("" + datetime.getHours()).padStart(2, '0'),
			        minute = ("" + datetime.getMinutes()).padStart(2, '0');
			    var result = "";
			
			    if (datetime.toDateString() === now.toDateString()) {
			        result = "";
			    } else if (datetime.toDateString() === new Date(now - 24 * 3600 * 1000).toDateString()) {
			        result = that.$t('chat.chat.yesterday');
			    } else if (now.getFullYear() === year) {
			        if (now.getTime() - datetime.getTime() < 7 * 24 * 3600 * 1000) {
			            var weekday = [that.$t('chat.chat.sunday'), that.$t('chat.chat.monday'), that.$t('chat.chat.tuesday'), that.$t('chat.chat.wednesday'), that.$t('chat.chat.thursday'), that.$t('chat.chat.friday'), that.$t('chat.chat.saturday')];
			            result = weekday[datetime.getDay()] + " ";
			        } else {
			            result = month + that.$t('global.moon') + date + that.$t('global.day');
			        }
			    } else {
			        result = year + that.$t('global.year') + month + that.$t('global.moon') + date + that.$t('global.day');
			    }
			    if (hour < 6) {
			        result += that.$t('chat.chat.beforedawn') + hour + ":" + minute;
			    } else if (hour < 11) {
			        result += that.$t('chat.chat.morning') + hour + ":" + minute;
			    } else if (hour < 13) {
			        result += that.$t('chat.chat.noon') + hour + ":" + minute;
			    } else if (hour < 18) {
			        result += that.$t('chat.chat.afternoon') + (hour - 12) + ":" + minute;
			    } else {
			        result += that.$t('chat.chat.evening') + (hour - 12) + ":" + minute;
			    }
			    return result;
			},
			InputFocus(e) {
				this.isOwO = false;
				this.InputBottom = e.detail.height;
			},
			InputBlur(e) {
				this.InputBottom = 0;
			},
			previewImage(image) {
				var imgArr = [];
				imgArr.push(image);
				//预览图片
				uni.previewImage({
					urls: imgArr,
					current: imgArr[0]
				});
			},
			toBanMsg(uid){
				var that = this;
				if(!uid){
					uni.showToast({
						title: that.$t('common.usernofound'),
						icon: 'none'
					})
					return false;
				}
				uni.navigateTo({
				    url: '/pages/manage/banuser?uid='+uid
				});
			},
			toDeleteMsg(id){
				var that = this;
				var token = "";
				if(localStorage.getItem('userinfo')){
					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					token=userInfo.token;
				}
				var data = {
					"msgid":id,
					"token":token
				}
				uni.showModal({
				    title: that.$t('chat.chat.suredelmsg'),
				    success: function (res) {
				        if (res.confirm) {
				            uni.showLoading({
				            	title: that.$t('common.loadmore')
				            });
				            that.$Net.request({
				            	url: that.$API.deleteMsg(),
				            	data:data,
				            	header:{
				            		'Content-Type':'application/x-www-form-urlencoded'
				            	},
				            	method: "get",
				            	dataType: 'json',
				            	success: function(res) {
				            		setTimeout(function () {
				            			uni.hideLoading();
				            		}, 1000);
				            		uni.showToast({
				            			title: res.data.msg,
				            			icon: 'none'
				            		})
				            		if(res.data.code==1){
				            			that.getMsgList();
				            		}
				            	},
				            	fail: function(res) {
				            		setTimeout(function () {
				            			uni.hideLoading();
				            		}, 1000);
				            		uni.showToast({
				            			title: that.$t('common.networkfail'),
				            			icon: 'none'
				            		})
				            	}
				            })
				        } else if (res.cancel) {
							
				        }
				    }
				});
			},
			getMsgList(isPage){
				var that = this;
				var token = "";
				if(localStorage.getItem('userinfo')){
					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					token=userInfo.token;
				}
				var page = that.page;
				if(isPage){
					page++;
				}
				// else{
				// 	用户加载更多数据时，不再加载数据
				// 	if(page > 1){
				// 		return false;
				// 	}
				// }
				that.$Net.request({
					url: that.$API.msgList(),
					data:{
						"token":token,
						"chatid":that.chatid,
						"limit":200,
						"page":page,
					},
					header:{
						'Content-Type':'application/x-www-form-urlencoded'
					},
					method: "get",
					dataType: 'json',
					success: function(res) {
						uni.stopPullDownRefresh();
						that.isLoad=0;
						that.moreText = that.$t('common.getmore');
						if(res.data.code==1){
							var list = res.data.data;
							if(list.length>0){
								if(isPage){
									that.page++;
									list = list.reverse();
									list = list.concat(that.msgList);
									that.msgList = list;
								}else{
									var lastid = list[0].id;
									if(that.lastid==lastid){
										return false;
									}else{
										that.lastid = lastid;
									}
									that.msgList = list.reverse();
								}
								var lastTime = that.msgList[that.msgList.length-1].created;
								if(lastTime > that.lastTime){
									setTimeout(() => {
										uni.pageScrollTo({
											duration: 0,
											scrollTop: 99999999
										})
									},100)
									that.lastTime = that.msgList[that.msgList.length-1].created;
								}
							}else{
								that.moreText = that.$t('common.nomoredata');
							}
						}
						var timer = setTimeout(function() {
							that.isLoading=1;
							clearTimeout('timer')
						}, 300)
					},
					fail: function(res) {
						uni.stopPullDownRefresh();
						that.moreText = that.$t('common.getmore');
						that.isLoad=0;
						var timer = setTimeout(function() {
							that.isLoading=1;
							clearTimeout('timer')
						}, 300)
					}
				})
			},
			getIsFollow(){
				var that = this;
				var token = "";
				if(localStorage.getItem('userinfo')){
					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					token=userInfo.token;
				}
				var data = {
					token:token,
					touid:that.toid,
				}
				that.$Net.request({
					url: that.$API.isFollow(),
					data:data,
					header:{
						'Content-Type':'application/x-www-form-urlencoded'
					},
					method: "get",
					dataType: 'json',
					success: function(res) {
						that.isFollow = res.data.code;
					},
					fail: function(res) {
						uni.showToast({
							title: that.$t('common.networkfail'),
							icon: 'none'
						})
					}
				})
			},
			getUserInfo(id){
				var that = this;
				var data = {
					"key":id,
				}
				that.$Net.request({
					url: that.$API.getUserInfo(),
					data:data,
					header:{
						'Content-Type':'application/x-www-form-urlencoded'
					},
					method: "get",
					dataType: 'json',
					success: function(res) {
						if(res.data.code==1){
							var userInfo = res.data.data;
							if(that.type==0){
								that.avatarstyle = "background-image:url("+res.data.data.avatar+");"
								that.avatar = res.data.data.avatar;
							}
							if(that.type==1){
								if(res.data.data.screenName){
									that.groupUserName = res.data.data.screenName;
								}else{
									that.groupUserName = res.data.data.name;
								}
								that.groupUserAvatar = res.data.data.avatar;
							}
						}
					},
					fail: function(res) {
						
					}
				});
			},
			getGroupInfo(id){
				var that = this;
				var data = {
					"id":id,
				}
				that.$Net.request({
					url: that.$API.groupInfo(),
					data:data,
					header:{
						'Content-Type':'application/x-www-form-urlencoded'
					},
					method: "get",
					dataType: 'json',
					success: function(res) {
						if(res.data.code==1){
							var userInfo = res.data.data;
							if(that.type==1){
								that.avatarstyle = "background-image:url("+res.data.data.pic+");"
								that.avatar = res.data.data.pic;
								that.groupUser =  res.data.data.uid;
								that.getUserInfo(that.groupUser);
							}
							that.ban =  res.data.data.ban;
						}
					},
					fail: function(res) {
						
					}
				});
			},
			sendMsg(){
				var that = this;
				var token = "";
				if(that.msg==""){
					return false;
				}
				if(localStorage.getItem('userinfo')){
					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					token=userInfo.token;
				}else{
					uni.showToast({
						title: that.$t('common.plslogin'),
						icon: 'none'
					})
					clearInterval(that.msgLoading);
					that.msgLoading = null
					uni.navigateTo({
						url: '/pages/user/login'
					});
					return false;
				}
				var data={
					"chatid":that.chatid,
					"token":token,
					"msg":that.msg,
					"type":0,
				}
				//添加一个新字段
				var curtime = Date.parse(new Date());
				var msg ={
					"created": curtime / 1000,
					"text":that.msg,
					"type": 0,
					"uid": that.uid,
					"userJson": that.userInfo
				}
				that.msgList.push(msg);
				setTimeout(() => {
					uni.pageScrollTo({
						duration: 0,
						scrollTop: 99999999
					})
				},100)
				that.$Net.request({
					url: that.$API.sendMsg(),
					data:data,
					header:{
						'Content-Type':'application/x-www-form-urlencoded'
					},
					method: "post",
					dataType: 'json',
					success: function(res) {
						if(res.data.code==1){
							that.getMsgList();
							that.msg = "";
						}else{
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
						}
					},
					fail: function(res) {
						uni.showToast({
							title: that.$t('common.networkfail'),
							icon: 'none'
						})
					}
				})
			},
			toJb(type) {
				var that = this;
				if(type==1){
					uni.navigateTo({
						url: '/pages/user/help?type=user&title='+that.name
					});
				}else{
					uni.navigateTo({
						url: '/pages/user/help?type=group&title='+that.name
					});
				}
			},
			goUserInfo(name,toid,type){
				var that = this;
				clearInterval(that.msgLoading);
				that.msgLoading = null
				var title = name + that.$t('common.nameinfo');
				var type="user";
				if(type==0){
					uni.redirectTo({
					    url: '/pages/contents/userinfo?title='+title+"&name="+name+"&uid="+toid+"&avatar="+encodeURIComponent(that.avatar)
					});
				}else{
					uni.navigateTo({
					    url: '/pages/contents/userinfo?title='+title+"&name="+name+"&uid="+toid+"&avatar="+encodeURIComponent(that.groupUserAvatar)
					});
				}
			},
			ToCopy(text) {
				var that = this;
				// #ifdef APP-PLUS
				uni.setClipboardData({
					data: text,
					success: () => {
						uni.showToast({ //提示
							title: that.$t('common.copysuccess')
						})
					}
				});
				// #endif
				// #ifdef H5 
				let textarea = document.createElement("textarea");
				textarea.value = text;
				textarea.readOnly = "readOnly";
				document.body.appendChild(textarea);
				textarea.select();
				textarea.setSelectionRange(0, text.length) ;
				uni.showToast({ //提示
					title: that.$t('common.copysuccess')
				})
				var result = document.execCommand("copy") 
				textarea.remove();
				// #endif
			},
			follow(type){
				var that = this;
				var token = "";
				if(localStorage.getItem('userinfo')){
					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					token=userInfo.token;
				}else{
					uni.showToast({
						title: that.$t('common.plslogin'),
						icon: 'none'
					})
					clearInterval(that.msgLoading);
					that.msgLoading = null
					uni.navigateTo({
						url: '/pages/user/login'
					});
					return false;
				}
				var data = {
					token:token,
					touid:that.toid,
					type:type,
				}
				that.isFollow = type;
				uni.showLoading({
					title: that.$t('common.loadmore')
				});
				that.$Net.request({
					url: that.$API.follow(),
					data:data,
					header:{
						'Content-Type':'application/x-www-form-urlencoded'
					},
					method: "get",
					dataType: 'json',
					success: function(res) {
						setTimeout(function () {
							uni.hideLoading();
						}, 1000);
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						that.getIsFollow();
					},
					fail: function(res) {
						setTimeout(function () {
							uni.hideLoading();
						}, 1000);
						uni.showToast({
							title: that.$t('common.networkfail'),
							icon: 'none'
						})
						that.getIsFollow();
					}
				})
			},
			goHistory(){
				var that = this;
				uni.redirectTo({
					url: '/pages/chat/history?id='+that.chatid
				});
			},
			upload(){
				let that = this;
				var token = "";
				if(localStorage.getItem('userinfo')){
					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					token=userInfo.token;
				}else{
					uni.showToast({
						title: that.$t('common.plslogin'),
						icon: 'none'
					})
					clearInterval(that.msgLoading);
					that.msgLoading = null
					uni.navigateTo({
						url: '/pages/user/login'
					});
					return false;
				}
				uni.chooseImage({
					count: 6, 
					sourceType: ['album', 'camera'], 
				    success: function (res) {
						uni.showLoading({
							title: that.$t('common.upload')
						});
						const tempFilePaths = res.tempFilePaths;
						for(let i = 0;i < tempFilePaths.length; i++) {
							const uploadTask = uni.uploadFile({
							  url : that.$API.upload(),
							  filePath: tempFilePaths[i],
							  name: 'file',
							  formData: {
							   'token': token
							  },
							  success: function (uploadFileRes) {
								  let count = 0;
								  count++;
								  if(count==tempFilePaths.length){
									  setTimeout(function () {
										uni.hideLoading();
									  }, 1000);
								  }
									var data = JSON.parse(uploadFileRes.data);
									//var data = uploadFileRes.data;
									// uni.showToast({
									// 	title: data.msg,
									// 	icon: 'none'
									// })
									if(data.code==1){
										that.sendURL(1,data.data.url);
									}
								},fail:function(){
									
								}
							});
						}
					}
				})
			},
			sendURL(type,url){
				var that = this;
				var token = "";
				if(!url){
					return false;
				}
				if(localStorage.getItem('userinfo')){
					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					token=userInfo.token;
				}else{
					uni.showToast({
						title: that.$t('common.plslogin'),
						icon: 'none'
					})
					uni.navigateTo({
						url: '/pages/user/login'
					});
					return false;
				}
				var data={
					"chatid":that.chatid,
					"token":token,
					"url":url,
					"type":type,
				}
				// 添加本地消息显示
				var curtime = Date.parse(new Date());
				var msg = {
					"created": curtime / 1000,
					"url": url,
					"type": type,
					"uid": that.uid,
					"userJson": that.userInfo
				};
				that.msgList.push(msg);
				setTimeout(() => {
					uni.pageScrollTo({
						duration: 0,
						scrollTop: 99999999
					});
				}, 100);
				that.$Net.request({
					url: that.$API.sendMsg(),
					data:data,
					header:{
						'Content-Type':'application/x-www-form-urlencoded'
					},
					method: "post",
					dataType: 'json',
					success: function(res) {
						if(res.data.code==1){
							that.getMsgList();
						}else{
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
						}
					},
					fail: function(res) {
						uni.showToast({
							title: that.$t('common.networkfail'),
							icon: 'none'
						})
					}
				})
			},
			toOwO(text){
				var that = this;
				that.OwOtype = text;
				if(text=="paopao"){
					that.owoList = that.owo.data.paopao.container;
				}
				if(text=="adai"){
					that.owoList = that.owo.data.adai.container;
				}
				if(text=="alu"){
					that.owoList = that.owo.data.alu.container;
				}
				if(text=="quyinniang"){
					that.owoList = that.owo.data.quyinniang.container;
				}
			},
			setOwO(data){
				var that = this;
				var text = data.data;
				that.msg+=text;
				that.isOwO = false;
			},
			OwO(){
				var that = this;
				that.isOwO = !that.isOwO;
			},
			markHtml(text){
				var that = this;
				text = that.replaceAll(text,"<","&lt;");
				text = that.replaceAll(text,">","&gt;");
				// #ifdef APP-PLUS || H5
				var owoList=that.owoTextList;
				for(var i in owoList){
					if(that.replaceSpecialChar(text).indexOf(owoList[i].data) != -1){
						text = that.replaceAll(that.replaceSpecialChar(text),owoList[i].data,"<img src='/"+owoList[i].icon+"' class='tImg' />")
					}
				}
				// #endif
				return text;
			},
			goChatInfo(){
				
			},
			replaceSpecialChar(text) {
				if(!text){
					return false;
				}
				text = text.replace(/&quot;/g, '"');
				text = text.replace(/&amp;/g, '&');
				text = text.replace(/&lt;/g, '<');
				text = text.replace(/&gt;/g, '>');
				text = text.replace(/&nbsp;/g, ' ');
				return text;
			},
			replaceAll(string, search, replace) {
				return string.split(search).join(replace);
			},
			showModal(e) {
				this.modalName = e.currentTarget.dataset.target
			},
			hideModal() {
				this.modalName = null
			},
			toBan(type){
				var that = this;
				var token = "";
				that.hideModal();
				if(localStorage.getItem('userinfo')){
					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					token=userInfo.token;
				}
				var data = {
					"id":that.chatid,
					"token":token,
					"type":type
				}
				var tips = that.$t('chat.chat.sureshieldother');
				if(that.type==1){
					tips = that.$t('chat.chat.sureshielall');
				}
				uni.showModal({
				    title: tips,
				    success: function (res) {
				        if (res.confirm) {
				            uni.showLoading({
				            	title: that.$t('common.loadmore')
				            });
				            that.$Net.request({
				            	url: that.$API.banChat(),
				            	data:data,
				            	header:{
				            		'Content-Type':'application/x-www-form-urlencoded'
				            	},
				            	method: "get",
				            	dataType: 'json',
				            	success: function(res) {
				            		setTimeout(function () {
				            			uni.hideLoading();
				            		}, 1000);
				            		uni.showToast({
				            			title: res.data.msg,
				            			icon: 'none'
				            		})
				            		if(res.data.code==1){
				            			that.getMsgList(false);
										// that.getGroupInfo(that.chatid);
										that.ban = that.uid;
				            		}
				            	},
				            	fail: function(res) {
				            		setTimeout(function () {
				            			uni.hideLoading();
				            		}, 1000);
				            		uni.showToast({
				            			title: that.$t('common.networkfail'),
				            			icon: 'none'
				            		})
				            	}
				            })
				        }
				    }
				});
			},
			toDelete(){
				var that = this;
				var token = "";
				that.hideModal();
				if(localStorage.getItem('userinfo')){
					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					token=userInfo.token;
				}
				var data = {
					"chatid":that.chatid,
					"token":token
				}
				uni.showModal({
				    title: that.$t('chat.chat.delsurechatroom'),
				    success: function (res) {
				        if (res.confirm) {
				            uni.showLoading({
				            	title: that.$t('common.loadmore')
				            });
				            that.$Net.request({
				            	url: that.$API.deleteChat(),
				            	data:data,
				            	header:{
				            		'Content-Type':'application/x-www-form-urlencoded'
				            	},
				            	method: "get",
				            	dataType: 'json',
				            	success: function(res) {
				            		setTimeout(function () {
				            			uni.hideLoading();
				            		}, 1000);
				            		uni.showToast({
				            			title: res.data.msg,
				            			icon: 'none'
				            		})
				            		if(res.data.code==1){
				            			that.back();
				            		}
				            	},
				            	fail: function(res) {
				            		setTimeout(function () {
				            			uni.hideLoading();
				            		}, 1000);
				            		uni.showToast({
				            			title: that.$t('common.networkfail'),
				            			icon: 'none'
				            		})
				            	}
				            })
				        }
				    }
				});
			},
			addGroup(){
				var that = this;
				clearInterval(that.msgLoading);
				that.msgLoading = null
				var chatid = that.chatid;
				uni.navigateTo({
				    url: '/pages/manage/addGroup?chatid='+chatid+"&postType=edit"
				});
			},
			// 语音聊天相关方法
			toggleVoiceMode() {
				this.isVoiceMode = !this.isVoiceMode;
				if (this.isVoiceMode) {
					// #ifdef H5
					this.voiceBtnText = this.$t('chat.chat.startrecord');
					// #endif
					// #ifdef APP-PLUS || MP
					this.voiceBtnText = this.$t('chat.chat.holdtalk');
					// #endif
				}
			},
			
			initRecorder() {
				var that = this;
				// #ifdef APP-PLUS || MP
				if (that.recorderManager) {
					that.recorderManager.onStart(() => {
						that.isRecording = true;
						that.voiceBtnText = that.$t('chat.chat.releaseend');
						that.startRecordTimer();
						that.isCancelRecording = false;
					});
					
					that.recorderManager.onStop((res) => {
						that.isRecording = false;
						that.voiceBtnText = that.$t('chat.chat.holdtalk');
						that.stopRecordTimer();
						// 如果是取消录音，不执行上传
						if (that.isCancelRecording) {
							that.isCancelRecording = false;
							that.touchStartY = null;
							uni.showToast({
								title: that.$t('chat.chat.recordcancel'),
								icon: 'none'
							});
							return;
						}
						that.isCancelRecording = false;
						that.touchStartY = null;
						if (res.duration < 1000) {
							uni.showToast({
								title: that.$t('chat.chat.recordshort'),
								icon: 'none'
							});
							return;
						}
						// APP/小程序自动上传
						that.uploadVoiceFile(res.tempFilePath, res.duration);
					});
					
					that.recorderManager.onError((res) => {
						that.isRecording = false;
						// #ifdef H5
						that.voiceBtnText = that.$t('chat.chat.startrecord');
						// #endif
						// #ifdef APP-PLUS || MP
						that.voiceBtnText = that.$t('chat.chat.holdtalk');
						// #endif
						that.stopRecordTimer();
						that.isCancelRecording = false;
						that.touchStartY = null;
						uni.showToast({
							title: that.$t('chat.chat.recordfail'),
							icon: 'none'
						});
					});
				}
				// #endif
			},
			
			// H5点击录音切换方法
			toggleH5Record() {
				var that = this;
				if (!that.isRecording) {
					// 开始录音 - 先检查是否已初始化
					if (!that.h5MediaRecorder) {
						that.initH5Recorder();
					} else {
						that.startH5Record();
					}
				} else {
					// 结束录音
					that.stopH5Record();
				}
			},
			
			// H5语音录制方法
			startH5Record() {
				var that = this;
				// #ifdef H5
				if (that.h5MediaRecorder && that.h5MediaRecorder.state === 'inactive') {
					that.h5AudioChunks = [];
					that.h5MediaRecorder.start();
					that.isRecording = true;
					that.voiceBtnText = that.$t('chat.chat.endrecord');
					that.startRecordTimer();
				} else {
					uni.showToast({
						title: that.$t('chat.chat.recordernoread'),
						icon: 'none'
					});
				}
				// #endif
			},
			
			stopH5Record() {
				var that = this;
				// #ifdef H5
				if (that.h5MediaRecorder && that.h5MediaRecorder.state === 'recording') {
					that.h5MediaRecorder.stop();
					that.isRecording = false;
					that.stopRecordTimer();
					// 显示选择对话框
					that.showH5RecordOptions();
				}
				// #endif
			},
			
			showH5RecordOptions() {
				var that = this;
				// #ifdef H5
				uni.showModal({
					title: that.$t('chat.chat.recordcomplete'),
					content: that.$t('chat.chat.sendvoicemessage'),
					confirmText: that.$t('global.send'),
					cancelText: that.$t('common.cancel'),
					success: function(res) {
						if (res.confirm) {
							// 发送语音
							if (that.h5AudioBlob) {
								var file = new File([that.h5AudioBlob], 'voice.mp3', { type: 'audio/mp3' });
								that.uploadH5VoiceFile(file);
							}
							that.voiceBtnText = that.$t('chat.chat.startrecord');
						} else {
							// 取消发送，清理录音数据
							that.h5AudioChunks = [];
							that.h5AudioBlob = null;
							that.voiceBtnText = that.$t('chat.chat.startrecord');
						}
					}
				});
				// #endif
			},
			
			initH5Recorder() {
				var that = this;
				// #ifdef H5
				// 检查浏览器是否支持MediaRecorder
				if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
					uni.showToast({
						title: that.$t('chat.chat.browservoicerecord'),
						icon: 'none'
					});
					return;
				}
				// 请求麦克风权限
				navigator.mediaDevices.getUserMedia({ audio: true })
					.then(function(stream) {
						that.h5Stream = stream;
						that.h5MediaRecorder = new MediaRecorder(stream);
						that.h5MediaRecorder.ondataavailable = function(event) {
							if (event.data.size > 0) {
								that.h5AudioChunks.push(event.data);
							}
						};
						that.h5MediaRecorder.onstop = function() {
							that.h5AudioBlob = new Blob(that.h5AudioChunks, { type: 'audio/mp3' });
							// 检查录音时长
							if (that.recordDuration < 1) {
								uni.showToast({
									title: that.$t('chat.chat.recordshort'),
									icon: 'none'
								});
								that.h5AudioChunks = [];
								that.h5AudioBlob = null;
								that.voiceBtnText = that.$t('chat.chat.startrecord');
								return;
							}
							// 不自动上传，等待用户选择
						};
						
						that.h5MediaRecorder.onerror = function(event) {
							that.isRecording = false;
							that.voiceBtnText = that.$t('chat.chat.startrecord');
							that.stopRecordTimer();
							uni.showToast({
								title: that.$t('chat.chat.recordfail'),
								icon: 'none'
							});
						};
						// 权限获取成功后，直接开始录音
						that.startH5Record();
					})
					.catch(function(err) {
						uni.showToast({
							title: that.$t('chat.chat.noallowmicrophone'),
							icon: 'none'
						});
					});
				// #endif
			},
			
			startRecord(e) {
				var that = this;
				if (that.recorderManager && !that.isRecording) {
					// 记录起始触摸位置
					that.touchStartY = e.touches[0].clientY;
					that.isCancelRecording = false;
					that.recorderManager.start({
						duration: 60000, // 最长60秒
						sampleRate: 16000,
						numberOfChannels: 1,
						encodeBitRate: 96000,
						format: 'mp3'
					});
				}
			},
			
			touchMove(e) {
				var that = this;
				// #ifdef APP-PLUS || MP
				if (that.isRecording && that.touchStartY) {
					var currentY = e.touches[0].clientY;
					var moveDistance = that.touchStartY - currentY;
					// 如果上划距离超过50px，显示取消提示
					if (moveDistance > 50) {
						that.voiceBtnText = that.$t('chat.chat.fingercancelsend');
						that.isCancelRecording = true;
					} else {
						that.voiceBtnText = that.$t('chat.chat.releaseend');
						that.isCancelRecording = false;
					}
				}
				// #endif
			},
			
			stopRecord() {
				var that = this;
				// #ifdef APP-PLUS || MP
				if (that.recorderManager && that.isRecording) {
					// 检查是否要取消录音
					if (that.isCancelRecording) {
						// 取消录音 - 先设置取消标志，再停止录音
						that.recorderManager.stop();
						// 状态重置在onStop回调中处理
					} else {
						// 正常停止录音
						that.recorderManager.stop();
					}
				}
				// #endif
			},
			
			cancelRecord() {
				var that = this;
				// #ifdef APP-PLUS || MP
				if (that.recorderManager && that.isRecording) {
					// 设置取消标志，然后停止录音
					that.isCancelRecording = true;
					that.recorderManager.stop();
					// 状态重置在onStop回调中处理
				}
				// #endif
			},
			
			startRecordTimer() {
				var that = this;
				that.recordDuration = 0;
				that.recordTimer = setInterval(() => {
					that.recordDuration++;
					if (that.recordDuration >= 60) {
						// #ifdef H5
						that.stopH5Record();
						// #endif
						// #ifdef APP-PLUS || MP
						that.stopRecord();
						// #endif
					}
				}, 1000);
			},
			
			stopRecordTimer() {
				var that = this;
				if (that.recordTimer) {
					clearInterval(that.recordTimer);
					that.recordTimer = null;
				}
			},
			
			uploadH5VoiceFile(file) {
				var that = this;
				var token = "";
				if (localStorage.getItem('userinfo')) {
					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					token = userInfo.token;
				} else {
					uni.showToast({
						title: that.$t('common.plslogin'),
						icon: 'none'
					});
					return;
				}
				
				uni.showLoading({
					title: that.$t('common.upload')
				});
				
				// 创建FormData对象
				var formData = new FormData();
				formData.append('file', file);
				formData.append('token', token);
				// 使用XMLHttpRequest上传
				var xhr = new XMLHttpRequest();
				xhr.open('POST', that.$API.upload(), true);
				xhr.onload = function() {
					setTimeout(function() {
						uni.hideLoading();
					}, 1000);
					if (xhr.status === 200) {
						try {
							var data = JSON.parse(xhr.responseText);
							if (data.code == 1) {
								that.sendVoiceMsg(data.data.url, that.recordDuration);
							} else {
								uni.showToast({
									title: data.msg || that.$t('common.networkerror'),
									icon: 'none'
								});
							}
						} catch (e) {
							uni.showToast({
								title: that.$t('common.networkerror'),
								icon: 'none'
							});
						}
					} else {
						uni.showToast({
							title: that.$t('common.networkerror'),
							icon: 'none'
						});
					}
				};
				xhr.onerror = function() {
					setTimeout(function() {
						uni.hideLoading();
					}, 1000);
					uni.showToast({
						title: that.$t('common.networkerror'),
						icon: 'none'
					});
				};
				xhr.send(formData);
			},
			
			uploadVoiceFile(filePath, duration) {
				var that = this;
				var token = "";
				if (localStorage.getItem('userinfo')) {
					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					token = userInfo.token;
				} else {
					uni.showToast({
						title: that.$t('common.plslogin'),
						icon: 'none'
					});
					return;
				}
				uni.showLoading({
					title: that.$t('common.upload')
				});
				uni.uploadFile({
					url: that.$API.upload(),
					filePath: filePath,
					name: 'file',
					formData: {
						'token': token
					},
					success: function(uploadFileRes) {
						setTimeout(function() {
							uni.hideLoading();
						}, 1000);
						var data = JSON.parse(uploadFileRes.data);
						if (data.code == 1) {
							// 传递录音时长
							that.sendVoiceMsg(data.data.url, duration);
						} else {
							uni.showToast({
								title: data.msg || that.$t('common.networkerror'),
								icon: 'none'
							});
						}
					},
					fail: function() {
						setTimeout(function() {
							uni.hideLoading();
						}, 1000);
						uni.showToast({
							title: that.$t('common.networkerror'),
							icon: 'none'
						});
					}
				});
			},
			
			sendVoiceMsg(url, duration) {
				var that = this;
				var token = "";
				if (localStorage.getItem('userinfo')) {
					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					token = userInfo.token;
				} else {
					uni.showToast({
						title: that.$t('common.plslogin'),
						icon: 'none'
					});
					return;
				}
				var data = {
					"chatid": that.chatid,
					"token": token,
					"url": url,
					"type": 2, // 语音消息类型
				};
				// 添加本地消息显示
				var curtime = Date.parse(new Date());
				var msg = {
					"created": curtime / 1000,
					"url": url,
					"type": 2,
					"uid": that.uid,
					"userJson": that.userInfo,
					"duration": duration || that.recordDuration
				};
				that.msgList.push(msg);
				setTimeout(() => {
					uni.pageScrollTo({
						duration: 0,
						scrollTop: 99999999
					});
				}, 100);
				that.$Net.request({
					url: that.$API.sendMsg(),
					data: data,
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					method: "post",
					dataType: 'json',
					success: function(res) {
						if (res.data.code == 1) {
							that.getMsgList();
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							});
						}
					},
					fail: function(res) {
						uni.showToast({
							title: that.$t('common.networkfail'),
							icon: 'none'
						});
					}
				});
			},
			
			playVoice(url) {
				var that = this;
				// #ifdef APP-PLUS || MP
				const innerAudioContext = uni.createInnerAudioContext();
				innerAudioContext.src = url;
				innerAudioContext.play();
				innerAudioContext.onPlay(() => {});
				innerAudioContext.onEnded(() => {
					innerAudioContext.destroy();
				});
				innerAudioContext.onError((res) => {
					uni.showToast({
						title: that.$t('chat.chat.playfail'),
						icon: 'none'
					});
					innerAudioContext.destroy();
				});
				// #endif
				// #ifdef H5
				const audio = new Audio(url);
				audio.play().then(() => {
				}).catch((error) => {
					uni.showToast({
						title: that.$t('chat.chat.playfail'),
						icon: 'none'
					});
				});
				// #endif
			},
			
			toUserContents(data){
				var that = this;
				var name = data.name;
				var title = data.name + that.$t('common.nameinfo');
				var id= data.uid;
				var type="user";
				uni.navigateTo({
				    url: '/pages/contents/userinfo?title='+title+"&name="+name+"&uid="+id+"&avatar="+encodeURIComponent(data.avatar)
				});
			},
		}
	}
</script>

<style>
page{
  padding-bottom: 100upx;
}
.cu-bar.foot{
	z-index: 998;
	background-color: #ffffff;
}

.dark .cu-bar.foot {
	background-color: #1c1c1c;
}

/* 语音聊天相关样式 */
.input-container {
	flex: 1;
	margin: 0 20rpx;
}

.voice-container {
	flex: 1;
	margin: 0 20rpx;
	display: flex;
	align-items: center;
}

.voice-btn {
	background-color: #f0f0f0;
	border: 1px solid #ddd;
	border-radius: 20rpx;
	padding: 20rpx 40rpx;
	text-align: center;
	color: #666;
	font-size: 28rpx;
	width: 100%;
	box-sizing: border-box;
	transition: all 0.2s ease;
	cursor: pointer;
	user-select: none;
}

.voice-btn:active {
	background-color: #e0e0e0;
	transform: scale(0.98);
}

.voice-btn.recording {
	background-color: #ff4444;
	color: #fff;
	border-color: #ff4444;
	animation: pulse 1s infinite;
}

@keyframes pulse {
	0% {
		transform: scale(1);
	}
	50% {
		transform: scale(1.02);
	}
	100% {
		transform: scale(1);
	}
}

.voice-message {
	display: flex;
	align-items: center;
	background-color: #f8f9fa;
	border-radius: 20rpx;
	padding: 20rpx 30rpx;
	min-width: 200rpx;
	max-width: 400rpx;
}

.voice-message .cuIcon-sound {
	font-size: 40rpx;
	margin-right: 20rpx;
}

.voice-message .voice-text {
	flex: 1;
	font-size: 28rpx;
	color: #333;
}

/* 夜间模式下的语音消息样式 */
.dark .voice-btn {
	background-color: #2c2c2c;
	border-color: #444;
	color: #ccc;
}

.dark .voice-btn:active {
	background-color: #3c3c3c;
}

.dark .voice-message {
	background-color: #2c2c2c;
}

.dark .voice-message .voice-text {
	color: #f1f1f1;
}
</style>
